﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using ATW.MT.BUS;
using ATW.MT.CommonClass;
using System.Data;

namespace ATW.MT.SellManage
{
    public partial class SupplyResponse : System.Web.UI.Page
    {
        bus_T_Respone response = new bus_T_Respone();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            try
            {
                if (!string.IsNullOrEmpty(Request.QueryString["uid"]))
                {
                    string uid = Request.QueryString["uid"];
                    if (common.filterChar(uid))
                    {
                        string title = txtTitle.Value.Trim();
                        string status = ddlStatus.SelectedValue;
                        string timeFrom = txtPubStart.Value.Trim();
                        string timeEnd = txtPubEnd.Value.Trim();
                        DateTime _timeFrom=new DateTime();
                        DateTime _timeEnd=new DateTime();
                        if (!common.filterChar(title))
                        {
                            Tips("查询条件中含有非法字符");
                            return;
                        }
                        if (timeFrom != "" && !DateTime.TryParse(timeFrom, out _timeFrom))
                        {
                            Tips("时间格式不正确！");
                            return;
                        }
                        if (timeEnd != "" && !DateTime.TryParse(timeEnd, out _timeEnd))
                        {
                            Tips("时间格式不正确！");
                            return;
                        }
                        DataTable dt = response.UserResponsePagerQuery(uid, title, status, timeFrom, timeEnd, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize);
                        if (dt != null && dt.Rows.Count > 0)
                        {
                            lblName.Text = dt.Rows[0]["tauName"].ToString();
                            AspNetPager1.RecordCount = Convert.ToInt32(dt.Rows[0]["totalPagesize"].ToString());
                        }
                        else
                        {
                            AspNetPager1.RecordCount = 0;
                        }
                        rpList.DataSource = dt;
                        rpList.DataBind();
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }
        protected void AspNetPager1_pageChanged(object sender, EventArgs e)
        {
            BindData();
        }
        protected void lbnArgs_Click(object sender, EventArgs e)
        {
            LinkButton lbn = (LinkButton)sender;
            string ResponeID = lbn.CommandArgument;
            string url = "../SellManage/ResponeDetail.aspx?ResponeID=" + ResponeID + "&r=" + new Random().Next(1000);
            OpenDialog("报价详情", url, "height=500,width=1377");
        }
        private void Tips(string s)
        {
            StringBuilder strScript = new StringBuilder();
            strScript.Append(@"<script language=javascript>
                var divTips=new jSharp.popUpDiv('divMsg');
                document.getElementById('msgContent').innerHTML='" + s + @"';
                divTips.Show();
                var t=setTimeout(function(){
                    divTips.Close();
                    clearTimeout(t);
                },1000);
            </script>");
            this.ClientScript.RegisterStartupScript(this.GetType(), "tips", strScript.ToString());
        }//提示
        /// <summary>
        /// 打卡模态窗口
        /// </summary>
        /// <param name="name">窗口名称</param>
        /// <param name="url">窗口url</param>
        /// <param name="args">窗口宽和高，不需要加单位(height=xxx,width=xxx )</param>
        private void OpenDialog(string name, string url, string args)
        {
            StringBuilder strScript = new StringBuilder();
            strScript.AppendFormat(@"<script language=javascript>
                                        window.open('{0}','{1}','z-lock=yes,top=300,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,channelmode=yes,status=no,{2}')
                                    </script>", url, name, args);
            this.ClientScript.RegisterStartupScript(this.GetType(), "openDialog", strScript.ToString());
        }
    }
}